


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>日志信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <style>
        body{
            background: #000;
            overflow: scroll;
        }
        .dialog_body{
            background: #000;
            color: #fff;
            white-space:normal;
            word-break:break-all;
            word-wrap:break-word;
            padding: 10px 10px 10px 10px;
        }
    </style>
</head>
<body id="main_body">
<div id="dialog_body" class="dialog_body">
    loading...
</div>
<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index'], function(){
        var $ = layui.$;
        function getQueryVariable(variable)
        {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        }
        var buildNumber = getQueryVariable("buildNumber");
        var jobName = getQueryVariable("jobName");
        //console.log(jobName + "----------buildNumber--------- "+buildNumber);
        function getData() {
            $.ajax({
                url: "/api/jenkins/buildHistoryLog",
                type: 'get',
                data: {"jobName": jobName, "number": buildNumber},
                success: function (data, textStatus) {
                    if (textStatus == 'success') {
                        if (typeof (data.code) == "undefined") {
                            console.log("----code = undefined----" + data.code);
                            //登入成功的提示与跳转
                            layer.msg('登录状态已过期', {offset: '15px', icon: 2, time: 1000},
                                function () {
                                    location.href = '/';
                                });
                        }
                        var resData = data.data;
                        var regStop = RegExp(/Finished:/);
                        if (resData.match(regStop)) {
                            console.log("----包含----");
                            window.clearInterval(t2) // 去除定时器
                        }
                        var reg = new RegExp("\n", "g");//g,表示全部替换
                        var logData = resData.replace(reg, "<br/>");
                        $("#dialog_body").html(logData);
                        //layer.msg(data.msg);
                        //$("html").scrollTop(1000);
                        window.scrollTo(document.body.scrollWidth, document.body.scrollHeight)
                    }
                }
            })
        }
        getData();
        var t2 = window.setInterval(function() {
            console.log('每隔2秒钟执行一次')
            getData();
        },2000)

        // //监听提交
        // form.on('submit(layuiadmin-app-form-submit)', function(data){
        //     var field = data.field; //获取提交的字段
        //     var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        //
        //     //提交 Ajax 成功后，关闭当前弹层并重载表格
        //     //$.ajax({});
        //     parent.layui.table.reload('LAY-app-content-list'); //重载表格
        //     parent.layer.close(index); //再执行关闭
        // });
    })
</script>
</body>
</html>